<template>
    <div class="page">
        <XLoginActionView 
        :data="loginData"
        @on-submit="submitLogin">
    </XLoginActionView>
</div>
</template>

<script>
import accountService from '@/network/service/accountService.js'
import XLoginActionView from '@/pages/login/view/XLoginActionView'

export default {
    components: {
        XLoginActionView
    },
    data() {
        return {
            loginData: {
                isLoading: false,
                data: {
                    phone: '',
                    password: ''
                }
            }
        }
    },
    mounted() {
        // var loginParam = this.$store.getters.loginParam;
        // if(loginParam != null) {
        //     this.data.data.phone = loginParam.phone;
        //     this.data.data.password = loginParam.password;
        // }
    },
    methods: {
        submitLogin(form) {
            var $this = this;
            form.isLoading = true;
            var params = form.data;
            accountService.login({
                phone: params.phone,
                password: params.password
            }).then(res => {
                let result = res.data;
                let code = result.rescode;
                var resmsg = result.msg;
                if (code == 100) {
                    $this.$store.commit('setAccount', result.data);
                    $this.$store.commit('setLoginParam', {
                        phone: params.phone,
                        password: params.password,
                    });
                    this.$router.push({
                        name: 'main'
                    });
                    this.$Message.success(resmsg);
                } else {
                    this.$Message.error(resmsg);
                }
                form.isLoading = false;
            }, res => {
                form.isLoading = false;
                this.$Message.error('服务器异常，请稍后再试！');
            })
        }
    }
}
</script>

<style scoped lang="less">
.page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}
</style>